package org.bbs.demo.reply.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.bbs.demo.reply.dto.ReplyDto;

@Mapper
public interface ReplyDao {
    @Insert("insert into bbsreply(r_id,topic_id,user_id,r_text,r_time,r_likes,r_reply_num)" +
            "values(#{r_id},#{topic_id},#{user_id},#{r_text},#{r_time},#{r_likes},#{r_reply_num})")
    public int addReply(ReplyDto replyDto);

    @Select("select user_id from bbsusers where user_id = #{user_id}")
    public String findUser(String user_id);

    @Select("select topic_id from bbstopic where topic_id = #{topic_id}")
    public String findTopic(String topic_id);

    @Update("update bbstopic set replys = replys + 1 where topic_id = #{topic_id}")
    public int updateReplyNum(String topic_id);
}
